package com.cxrj.zhsq.activityManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.activityManage.entity.PropertyActivity;
import com.cxrj.zhsq.activityManage.entity.PropertyActivityType;
import com.cxrj.zhsq.activityManage.service.ActivityService;

@RestController
public class ActivityController {

	@Resource
	private ActivityService activityService;

	/**
	 * 分页查询活动类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyActivityTypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectPropertyActivityTypes(HttpServletRequest request, HttpServletResponse response) {
		return activityService.seleteActivityTypePage(request, response);
	}

	/**
	 * 分页查询活动
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyActivitys", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectPropertyActivitys(HttpServletRequest request, HttpServletResponse response) {
		return activityService.seleteActivityPage(request, response);
	}

	/**
	 * 添加活动类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyActivityType", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyActivityType(PropertyActivityType propertyActivityType, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyActivityType.setS1(request.getSession().getAttribute("communityId").toString());
			resultMap = activityService.insertActivityType(propertyActivityType);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 添加活动
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyActivity", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyActivity(PropertyActivity propertyActivity, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyActivity.setS1(request.getSession().getAttribute("communityId").toString());
			resultMap = activityService.insertActivity(propertyActivity);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改活动类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyActivityType", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyActivityType(PropertyActivityType propertyActivityType, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = activityService.updateActivityType(propertyActivityType);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改活动
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyActivity", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyActivity(PropertyActivity propertyActivity, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = activityService.updateActivity(propertyActivity);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 根据id查询活动类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyActivityTypeById", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyActivityTypeById(String id, HttpServletRequest request) {
		return activityService.seleteActivityTypeById(id);
	}

	/**
	 * 根据id查询活动
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyActivityById", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyActivityById(String id, HttpServletRequest request) {
		return activityService.seleteActivityById(id);
	}

	/**
	 * 查询使用活动类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyActivityTypeByAll", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyActivityTypeByAll(HttpServletRequest request) {
		return activityService.selectActivityTypeByAll(request);
	}
}
